package com.library.controller;

import com.library.entity.OaAttendanceRecord;
import com.library.entity.OaAttendanceRecordExt;
import com.library.entity.OaAttendanceRecordReq;
import com.library.entity.OaDepartmentUserLinkExt;
import com.library.service.OaAttendanceRecordServiceImpl;
import com.library.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ido
 * @since 2024-12-14
 */
@Controller
public class OaAttendanceRecordController {

    public static final String prefix = "/api/oaAttendanceRecord";

    @Autowired
    private OaAttendanceRecordServiceImpl oaAttendanceRecordService;

    @RequestMapping("/oaAttendanceRecord.html")
    public ModelAndView adminBooks() {
        ModelAndView modelAndView = new ModelAndView("oaAttendanceRecord");
        return modelAndView;
    }

    @RequestMapping(path = prefix + "/list",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult list(@RequestBody OaAttendanceRecordExt oaDepartmentUserLink) {
        List<OaAttendanceRecordExt> list = this.oaAttendanceRecordService.list(oaDepartmentUserLink);
        return BaseResult.successWithData(list);
    }

    // 打卡操作
    @RequestMapping(path = prefix + "/clockin",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult clockin(@RequestBody OaAttendanceRecordReq oaDepartmentUserLink) {
        this.oaAttendanceRecordService.add(oaDepartmentUserLink);
        return BaseResult.success();
    }

    @RequestMapping(path = prefix + "/detail",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult detail(@RequestBody OaAttendanceRecord oaDepartmentUserLink) {
        OaAttendanceRecord oaDepartmentUserLink1 = this.oaAttendanceRecordService.detail(oaDepartmentUserLink);
        return BaseResult.successWithData(oaDepartmentUserLink1);
    }

    @RequestMapping(path = prefix + "/detailByLast",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult detailByLast(@RequestBody OaAttendanceRecord oaDepartmentUserLink) {
        OaAttendanceRecordExt oaDepartmentUserLink1 = this.oaAttendanceRecordService.detailByLast(oaDepartmentUserLink);
        return BaseResult.successWithData(oaDepartmentUserLink1);
    }
}
